#include "TcpClient.h"

using namespace std;
using namespace network;

void TcpClient::clientHandler(int fd, EventType event_type, void *context) {
    try {
        if (event_type == EventType::Read) {
            clientRecv();
        }
        else if (event_type == EventType::Write) {
            clientSend();
        }
        else if (event_type == EventType::Close) {
            clientClose();
        }
    }
    catch (const exception &e) {}
}

void TcpClient::initHandler() {
    reactor_->registerHandler(getFd(), EventType::Read,
                              bind(&TcpClient::clientHandler, this, placeholders::_1, placeholders::_2,
                                   placeholders::_3),
                              nullptr);
}
